#!/bin/bash

function my_build
{
./configure \
--prefix=$MY_PREFIX \
--extra-cflags=$MY_EXTRA_CFLAGS \
--disable-cli \
--enable-shared \
--enable-pic \
--host=$MY_HOST \
--cross-prefix=$MY_CROSS_PREFIX \
--sysroot=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
make clean
make -j8
make install
}

#arm64-v8a
export CC=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang
export CXX=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++
MY_PREFIX=./Android/arm64-v8a
MY_EXTRA_CFLAGS="-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O2 -DNDEBUG  -fPIC --target=aarch64-none-linux-android21 --gcc-toolchain=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64"
MY_HOST=aarch64-linux-android
MY_CROSS_PREFIX=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-
my_build

#armeabi-v7a
export CC=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang
export CXX=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang++
MY_PREFIX=./Android/armeabi-v7a
MY_EXTRA_CFLAGS="-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security   -Oz -DNDEBUG  -fPIC --gcc-toolchain=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64"
MY_HOST=armv7a-linux-android
MY_CROSS_PREFIX=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
my_build

#x86_64
export CC=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang
export CXX=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang++
MY_PREFIX=./Android/x86_64
MY_EXTRA_CFLAGS="-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O2 -DNDEBUG  -fPIC --target=x86_64-none-linux-android21 --gcc-toolchain=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64"
MY_HOST=x86_64-linux-android
MY_CROSS_PREFIX=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-
my_build

#x86
export CC=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android24-clang
export CXX=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android24-clang++
MY_PREFIX=./Android/x86
MY_EXTRA_CFLAGS="-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O2 -DNDEBUG  -fPIC --target=i686-none-linux-android21 --gcc-toolchain=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64"
MY_HOST=i686-linux-android
MY_CROSS_PREFIX=~/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-
my_build